import requests

from math import radians, cos, sin, asin, sqrt

def geocode(address):
    parameters = {'address': address, 'key': 'STHBZ-N7F63-VW43G-YTNKI-CAV5E-RQBS4'}
    base = 'https://apis.map.qq.com/ws/geocoder/v1/?address='
    response = requests.get(base, parameters)
    answer = response.json()
    print(answer)
    lon = float(answer['result']['location']['lng'])
    lat = float(answer['result']['location']['lat'])
    return [lon,lat]


def distance(lon1, lat1, lon2, lat2):
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
    c = 2 * asin(sqrt(a))
    r = 6371  # 地球平均半径，单位为公里
    return c * r * 1000


if __name__ == '__main__':
    print(geocode('西安市浐灞生态区御锦城'))